﻿// -----------------------------------------------------------------------
// <copyright file="VehicleInGarage.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [Flags]
    public enum eVehicleStatus
    {
        InRepair = 1,
        Repaired = 2,
        Paid = 3
    }

    public class VehicleInGarage
    {
        private string m_OwnerName;
        private string m_OwnerPhone;
        private Vehicle m_CurrentVehicle;
        private eVehicleStatus m_CurrentStatus = eVehicleStatus.InRepair;

        public VehicleInGarage(Vehicle i_Vehicle, string i_Name, string i_Phone)
        {
            m_OwnerName = i_Name;
            m_OwnerPhone = i_Phone;
            m_CurrentVehicle = i_Vehicle;
        }

        internal eVehicleStatus CurrentStatus
        {
            get { return m_CurrentStatus; }
            set { m_CurrentStatus = value; }
        }
        
        internal Vehicle CurrentVehicle
        {
            get { return m_CurrentVehicle; }
            set { m_CurrentVehicle = value; }
        }

        internal string OwerName
        {
            get { return m_OwnerName; }
        }

        internal string OwnerPhone
        {
            get { return m_OwnerPhone; }
        }
        
        internal void ChangeCarStatus(eVehicleStatus i_NewStatus)
        {
            CurrentStatus = i_NewStatus;
        }

        internal void AddMaxAirPressure()
        {
            m_CurrentVehicle.AddMaxAirPressureToAllTires();
        }

        internal void RefuelGasTank(eTypeOfFuel i_FuelType, float i_AmountToAdd)
        {
            if (m_CurrentVehicle.SourceOfEnergy is Fuel)
            {
                Fuel fuelEnergySource = (Fuel) m_CurrentVehicle.SourceOfEnergy;
                fuelEnergySource.Refueling(i_FuelType, i_AmountToAdd);
            }
            else
            {
                throw new ArgumentException("This vehicle is electric engined! Cannot fill fuel.");
            }
            
            m_CurrentVehicle.CalculatePercentEnergyLeft();
        }

        internal void ChargeBattery(float i_AmountToAdd)
        {
            if (m_CurrentVehicle.SourceOfEnergy is Electric)
            {
                Electric fuelEnergySource = (Electric)m_CurrentVehicle.SourceOfEnergy;
                fuelEnergySource.ChargeBattery(i_AmountToAdd);
            }
            else
            {
                throw new ArgumentException("This vehicle is fuel engined! Cannot charge with electricity.");
            }

            m_CurrentVehicle.CalculatePercentEnergyLeft();
        }

        /// <summary>
        /// Collects info about vehicle into string and adds info about customer
        /// </summary>
        /// <param name="o_VehicleData">string in which all data is being collected</param>
        internal void GetVehicleData(ref StringBuilder o_VehicleData)
        {
            m_CurrentVehicle.GetVehicleData(ref o_VehicleData);
            o_VehicleData.AppendFormat("{0}Owner's name: {1}{0}Owner's phone: {2}{0}{0}Car status in the garage: {3}", Environment.NewLine, OwerName, OwnerPhone, CurrentStatus.ToString());
        }
    }
}
